package com.patterns.singleton;

/**
 * 饿汉式单例模式
 * 初始化实例对象
 * @author huangke
 *
 */
public class SingletonDemo1 {
	private static SingletonDemo1 instance = new SingletonDemo1();
	
	private SingletonDemo1(){
		// >> 防止反射漏洞创建对象
//		if(null != instance){
//			throw new RuntimeException("检测非法对象创建");
//		}
	}
	
	public static SingletonDemo1 getInstance(){
		return instance;
	}
}

class Test{
	SingletonDemo1 demo = SingletonDemo1.getInstance();
}
